package com.yp.infrastructure.mvc.i18n;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.MessageSource;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class I18nMessageSourceManager extends I18nAbstractMessageSourceManager implements IMessageSourceProvider {

    private static ReloadableResourceBundleMessageSource messageSource = null;

    @Override
    public MessageSource getMessageSource() {
        if (null != messageSource) return messageSource;
        messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setBasename("classpath:common");
        messageSource.setDefaultEncoding("UTF-8");
        return messageSource;
    }

    @Override
    public IMessageSourceManager create() {
        return this;
    }
}
